// 第一
$.ajax({
    type: "post",
    async: true, //异步执行
    url: "sy/nydsj/lsjg",
    dataType: "json", //返回数据形式为json
    success: function (json) {
        var jsonarray= $.parseJSON(json);
        var myChart = echarts.init(document.getElementById('main'));
        option = {
            tooltip: {
                trigger: 'axis'
            },
            grid: {
                x: '0%',
                x2: '5%',
                y: '5%',
                y2: '40%',
                containLabel: true//左侧刻度
            },
            xAxis: {
                type: 'category',
                // boundaryGap:false,
                data: ["2016", "2017", "2018"],
                textStyle: {
                    color: "red",
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                }
            },
            yAxis: {
                type: 'value',
                textStyle: {
                    color: '#fff'
                },
                axisLabel: {
                    formatter: '{value}',
                    textStyle: {
                        color: '#fff'
                    }
                }
            },
            series: []
        };
        var jsonObj = JSON.parse(jsonarray.name);
        $.each(jsonObj, function (index, item) {
            var newArray = {};
            newArray.name = item.category;
            newArray.type = 'line';
            newArray.stack = '总量';
            newArray.data = [];
            option.series.push(newArray);
        });
        var jsondata = JSON.parse(jsonarray.data);
        $.each(jsondata, function (index, item) {
            for (var i = 0; i < option.series.length; i++) {
                if (item.category == option.series[i].name) {
                    option.series[i].data.push(item.price);
                }

            }
        });
        myChart.setOption(option);
    },
    error: function (errorMsg) {
        alert("请求数据失败");
    }
});
